package com.xpu.cos.controller;

import java.util.Arrays;
import java.util.Map;

import com.xpu.cos.entity.GoodsEntity;
import com.xpu.cos.result.Result;

import com.xpu.cos.result.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xpu.cos.entity.GoodsEntity;
import com.xpu.cos.service.GoodsService;
import com.xpu.cos.utils.PageUtils;
import com.xpu.cos.utils.Query;

import javax.annotation.Resource;


/**
 * 
 *
 * @author wsh
 * @email renren@gmail.com
 * @date 2024-01-03 11:23:12
 */
@RestController
@RequestMapping("/cos/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
   // @RequiresPermissions(":goods:list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);
        return Result.ok().build(page, ResultCodeEnum.SUCCESS);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
   // @RequiresPermissions(":goods:info")
    public Result info(@PathVariable("id") Integer id){
		GoodsEntity goods = goodsService.getById(id);
        return Result.ok().build(goods, ResultCodeEnum.SUCCESS);
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
   // @RequiresPermissions(":goods:save")
    public Result save(@RequestBody GoodsEntity goods){
		goodsService.save(goods);

        return Result.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions(":goods:update")
    public Result update(@RequestBody GoodsEntity goods){
		goodsService.updateById(goods);
        return Result.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions(":goods:delete")
    public Result delete(@RequestBody Integer[] ids){
		goodsService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }
}
